<?php
include_once("./_common.php");
include_once("$g4[path]/m/branch/adm_head.php");

print_r($_SESSION['signVal']);

if ($w == "u")
{
	$sql = "SELECT *
			  FROM visit_record
			 WHERE id = '$id'";
	$rst = sql_query($sql);
	$write = mysql_fetch_assoc($rst);

	$store_num = $write['vi_area'];
	$this_year = date("Y");
	$sql2 = "SELECT y{$this_year}
			   FROM month_avg
			  WHERE store_num = '$store_num'";
	$rst2 = sql_query($sql2);
	$write2 = mysql_fetch_assoc($rst2);
	$this_str = $write2["y".$this_year];
	$vi_month = explode(",", $this_str);
	//print_r2($vi_month);
}
else
{
	$w = "";

	$store_num = $_GET['branch'];
	$this_year = date("Y");
	$sql = "SELECT y{$this_year}
			  FROM month_avg
			 WHERE store_num = '$store_num'";
	$rst = sql_query($sql);
	$write2 = mysql_fetch_assoc($rst);
	$this_str = $write2["y".$this_year];
	$vi_month = explode(",", $this_str);
}
?>

<style>
div.wrap {width:98%;text-align:center;margin:0 auto;font-family:"돋음, Tahoma, 굴림";font-size:9pt;background-color:#fff}
div.title_wrap {margin-top:30px;}
div.title_wrap h3 {width:160px;text-align:center;margin:0 auto; font-family:"나눔고딕";color:#fff;xborder:2px solid #5970a4; padding:7px 0px; background-color:#5970a4;}
div.table1 {}
div.table1 p {text-align:left;margin:5px 0;}
table.info1 {border:2px solid #5970a4;width:98%;}
table.info1 tr {height:40px;border-top:1px solid #d9d9d9;}
table.info1 th {border-top:1px solid #fff;xborder-right:1px solid #fff;background-color:#5970a4; xfont-weight:normal; text-align:left; padding-left:5px;height:39px; color:#fff;}
table.info1 td {border-top:1px solid #ccc;border-right:1px solid #ccc;border-left:1px solid #ccc;text-align:left;padding-left:10px;}
div.table2 {}
table.info2 {border:2px solid #5970a4;width:98%; margin-top:20px;}
table.info2 tr {height:40px;border-top:1px solid #d9d9d9;}
table.info2 th {border-top:1px solid #fff;xborder-right:1px solid #fff;background-color:#5970a4; xfont-weight:normal; text-align:left; padding-left:5px;height:39px; color:#fff;}
table.info2 td {border-top:1px solid #ccc;border-right:1px solid #ccc;border-left:1px solid #ccc;text-align:left;padding-left:10px;}
.txtwd {width:95%}
.tareawd {width:96%}
div.table2 p {text-align:right}
span.xthtxt {color:red;font-size:15px;}
span.xtdtxt {font-weight:bold}
</style>

<div class="wrap">
	<br />
	<img src="<?php echo $g4['path']?>/m/img/branch_tit.jpg" />
	<div class="title_wrap">
		<h3>방 문 일 지</h3>
	</div>
	<form action="<?php echo $g4['path']?>/m/android/visit_update_a.php" method="post" enctype="multipart/form-data">
		<input type="hidden" name="w" value="<?php echo $w?>" />
		<input type="hidden" name="id" value="<?php echo $id?>" />
		<input type="hidden" name="vi_area" value="<?php echo $branch_num;?>" />
		<div class="table1">
			<?php
			if ($w == "")
			{
				$sqlw = "select vi_area, count(*) from visit_record where vi_area = '$branch_num'";
				$rstw = sql_query($sqlw);
				$liw = mysql_fetch_assoc($rstw);
				$this_no = $liw['count(*)'] + 1;
				//echo $this_no;
			?>
			<p>No. : <?php echo "<span class='xtdtxt'>".$this_no."</span>";?></p>
			<input type="hidden" name="vi_no" value="<?php echo $this_no?>" />
			<?
			}
			else if ($w == "u")
			{
			?>
			<p>No. : <?php echo "<span class='xtdtxt'>".$write['vi_no']."</span>";?></p>
			<?
			}
			?>
			<table class="info1" border=0 cellspacing=0 cellpadding=0>
			<colgroup>
			<col width="118px" />
			<col width="" />
			</colgroup>
			<tr>
			<th><span class="xthtxt">*</span> 방문일자</th>
			<td>
				<?php
				if ($w == "")
				{
					$today = date("Y-m-d");
					$year = substr($today,2,2);
					$month = substr($today,5,2);
					$date = substr($today,8,2);
					$today_str = "20".$year."년 ".$month."월 ".$date."일";

					$time = date("a:h:i:s");
					if (substr($time,0,3) == "am:")
					{
						$ampm = "오전 ";
					}
					else if (substr($time,0,3) == "pm:")
					{
						$ampm = "오후 ";
					}
					$time_str = $ampm.date("h : i : s");

					echo "<span class='xtdtxt'>".$today_str."</span>";
				?>
				<input type="hidden" name="vi_date" value="<?php echo $today_str?>" />
				<?
				}
				else if ($w == "u")
				{
					echo "<span class='xtdtxt'>".$write['vi_date']."</span>";
				?>
				<input type="hidden" name="vi_date" value="<?php echo $write['vi_date']?>" />
				<?
				}
				?>
			</td>
			</tr>
			<tr>
			<th>구분</th>
			<td>
				<table width="100%" border=0 cellspacing=0 cellpadding=0>
					<tr style="border:none; height:25px;">
						<td style="border:none;"><input type="radio" tabindex=1 name="vi_flag" class="vi_flag vi_f1" value="감리" <?php echo $w == "" ? "checked" : ""?> />감리</td>
						<td style="border:none;"><input type="radio" tabindex=1 name="vi_flag" class="vi_flag vi_f2" value="정기점검" />정기점검</td>
					</tr>
					<tr style="border:none; height:25px;">
						<td style="border:none;"><input type="radio" tabindex=1 name="vi_flag" class="vi_flag vi_f2" value="분쟁" />분쟁</td>
						<td style="border:none;"><input type="radio" tabindex=1 name="vi_flag" class="vi_flag vi_f2" value="위반사항" />위반사항</td>
					</tr>
				</table>
			</td>
			</tr>
			<script>
			$(".vi_flag").val(["<?php echo $write['vi_flag']?>"]);
			$(".vi_f1").click(function() {
				$(".flag_hide").hide();
			});
			$(".vi_f2").click(function() {
				$(".flag_hide").show();
			});
			</script>
			<tr>
			<th><span class="xthtxt">*</span> 방문자</th>
			<td>
				<?php

				$mb = get_member($my_id);
				
				if ($w == "")
				{
					echo "<span class='xtdtxt'>".$mb['mb_name']."</span>";
				?>
					<input type="hidden" name="vi_name1" value="<?php echo $mb['mb_name']?>" />
				<?
				}
				else if ($w == "u")
				{
					echo "<span class='xtdtxt'>".$write['vi_name1']."</span>";
				?>
					<input type="hidden" name="vi_name1" value="<?php echo $write['vi_name1']?>" />
				<?
				}
				?>
			</td>
			</tr>
			<tr>
			<th><span class="xthtxt">*</span> 방문시간</th>
			<td>
				<?php
				if ($w == "") {
					echo "<span class='xtdtxt'>".$time_str."</span>";
				?>
					<input type="hidden" name="vi_time" value="<?php echo $time_str?>" />
				<? } else if ($w == "u") {
					echo "<span class='xtdtxt'>".$write['vi_time']."</span>";
				?>
					<input type="hidden" name="vi_time" value="<?php echo $write['vi_time']?>" />
				<? } ?>
			</td>
			</tr>
			</table>
		</div>
		<div class="table2">
			<table class="info2" border=0 cellspacing=0 cellpadding=0>
			<colgroup>
			<col width="118px" />
			<col width="" />
			</colgroup>
			<tr>
			<th><span class="xthtxt">*</span> 점명</th>
			<td>
				<?php echo "<span class='xtdtxt'>".$store."</span>"?>
				<input type="hidden" name="vi_store" value="<?php echo $store?>" />
			</td>
			</tr>
			<tr>
			<th><span class="xthtxt">*</span> 점주명</th>
			<td>
				<?php
				$sqlr = "select mb_name from g4_member where mb_1 = '$store'";
				$rstr = sql_query($sqlr);
				$namer = mysql_fetch_assoc($rstr);
				echo "<span class='xtdtxt'>".$namer['mb_name']."</span>";
				?>
				<input type="hidden" name="vi_name2" value="<?php echo $namer['mb_name']?>" />
			</td>
			</tr>
			<tr class="flag_hide">
			<th>직원수</th>
			<td style="padding:0px;"><input style="height:100%;margin:0px;" type="text" class="txtwd" tabindex=2 name="vi_count" value="<?php echo $write['vi_count']?>" /></td>
			</tr>
			<tr class="flag_hide">
			<th>평균고객수</th>
			<td style="padding:0px;"><input style="height:100%;margin:0px;" type="text" class="txtwd" tabindex=3 name="vi_avg" value="<?php echo $write['vi_avg']?>" /></td>
			</tr>
			<tr class="flag_hide">
			<th>금일매출현황</th>
			<td style="padding:0px;"><input style="height:100%;margin:0px;" type="text" class="txtwd" tabindex=4 name="vi_sales" value="<?php echo $write['vi_sales']?>" /></td>
			</tr>
			<tr class="flag_hide">
			<th>
				월 평균 매출<br />
				<?php if($w == "") { ?>
				<span style="cursor:pointer" class="bt_plus"><img src="<?php echo $g4['path']?>/m/branch/img/plus_btn.gif" /></span>
				&nbsp;&nbsp;&nbsp;
				<span style="cursor:pointer" class="bt_minu"><img src="<?php echo $g4['path']?>/m/branch/img/minu_btn.gif" /></span>
				<? } ?>
			</th>
			<td>
				<span class="vm1s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 1월
					<input type="text" class="vm1 vm" width="0px" name="vi_month0" tabindex=5 value="<?php echo $vi_month['0']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<div class="vm2d"></div>
				<div class="vm3d"></div>
				<div class="vm4d"></div>
				<div class="vm5d"></div>
				<div class="vm6d"></div>
				<div class="vm7d"></div>
				<div class="vm8d"></div>
				<div class="vm9d"></div>
				<div class="vm10d"></div>
				<div class="vm11d"></div>
				<div class="vm12d"></div>
				
				<span class="vm2s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 2월
					<input type="text" class="vm2 vm" width="30px" name="vi_month1" tabindex=6 value="<?php echo $vi_month['1']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm3s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 3월
					<input type="text" class="vm3 vm" width="30px" name="vi_month2" tabindex=7 value="<?php echo $vi_month['2']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm4s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 4월
					<input type="text" class="vm4 vm" width="30px" name="vi_month3" tabindex=8 value="<?php echo $vi_month['3']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm5s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 5월
					<input type="text" class="vm5 vm" width="30px" name="vi_month4" tabindex=9 value="<?php echo $vi_month['4']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm6s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 6월
					<input type="text" class="vm6 vm" width="30px" name="vi_month5" tabindex=10 value="<?php echo $vi_month['5']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm7s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 7월
					<input type="text" class="vm7 vm" width="30px" name="vi_month6" tabindex=11 value="<?php echo $vi_month['6']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm8s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 8월
					<input type="text" class="vm8 vm" width="30px" name="vi_month7" tabindex=12 value="<?php echo $vi_month['7']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm9s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 9월
					<input type="text" class="vm9 vm" width="30px" name="vi_month8" tabindex=13 value="<?php echo $vi_month['8']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm10s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 10월
					<input type="text" class="vm10 vm" width="30px" name="vi_month9" tabindex=14 value="<?php echo $vi_month['9']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm11s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 11월
					<input type="text" class="vm11 vm" width="30px" name="vi_month10" tabindex=15 value="<?php echo $vi_month['10']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span> <br />
				</span>
				<span class="vm12s">
					<?php echo substr(date("Y-m-d"),0,4);?>년 12월
					<input type="text" class="vm12 vm" width="30px" name="vi_month11" tabindex=16 value="<?php echo $vi_month['11']?>" onchange="checkNumber()" />
					<span style="color:red">숫자만 입력</span>
				</span>
			</td>
			</tr>
			<?php if($w == "") { ?>
			<script>
			window.onload = function() {
				var vm2s = $(".vm2s").detach();
				var vm3s = $(".vm3s").detach();
				var vm4s = $(".vm4s").detach();
				var vm5s = $(".vm5s").detach();
				var vm6s = $(".vm6s").detach();
				var vm7s = $(".vm7s").detach();
				var vm8s = $(".vm8s").detach();
				var vm9s = $(".vm9s").detach();
				var vm10s = $(".vm10s").detach();
				var vm11s = $(".vm11s").detach();
				var vm12s = $(".vm12s").detach();

				$(".bt_plus").click(function() {
					var vmp = $(".vm").length;
					if(vmp == "1") {
						$(".vm2d").html(vm2s);
					} else if (vmp == "2") {
						$(".vm3d").html(vm3s);
					} else if (vmp == "3") {
						$(".vm4d").html(vm4s);
					} else if (vmp == "4") {
						$(".vm5d").html(vm5s);
					} else if (vmp == "5") {
						$(".vm6d").html(vm6s);
					} else if (vmp == "6") {
						$(".vm7d").html(vm7s);
					} else if (vmp == "7") {
						$(".vm8d").html(vm8s);
					} else if (vmp == "8") {
						$(".vm9d").html(vm9s);
					} else if (vmp == "9") {
						$(".vm10d").html(vm10s);
					} else if (vmp == "10") {
						$(".vm11d").html(vm11s);
					} else if (vmp == "11") {
						$(".vm12d").html(vm12s);
					} else if (vmp == "12") {
						alert("더이상 추가할 수 없습니다.");
					}
				});

				$(".bt_minu").click(function() {
					var vmm = $(".vm").length;
					if(vmm == "1") {
						alert("더이상 삭제할 수 없습니다.");
					} else if (vmm == "2") {
						$(".vm2d").detach();
					} else if (vmm == "3") {
						$(".vm3d").detach();
					} else if (vmm == "4") {
						$(".vm4d").detach();
					} else if (vmm == "5") {
						$(".vm5d").detach();
					} else if (vmm == "6") {
						$(".vm6d").detach();
					} else if (vmm == "7") {
						$(".vm7d").detach();
					} else if (vmm == "8") {
						$(".vm8d").detach();
					} else if (vmm == "9") {
						$(".vm9d").detach();
					} else if (vmm == "10") {
						$(".vm10d").detach();
					} else if (vmm == "11") {
						$(".vm11d").detach();
					} else if (vmm == "12") {
						$(".vm12d").detach();
					}
				});
			}
			</script>
			<? } ?>
			
			<tr class="flag_hide">
			<th>이벤트현황</th>
			<td style="padding:0px;"><input style="height:100%;margin:0px;" type="text" class="txtwd" tabindex=17 name="vi_event" value="<?php echo $write['vi_event']?>" /></td>
			</tr>
			<tr class="flag_hide">
			<th>홀 유지 관리상태</th>
			<td>
				<input type="radio" name="vi_hall" value="0" <?php echo $write['vi_hall']=="0" ? "checked":""?> /> 양호
				&nbsp;&nbsp;&nbsp;
				<input type="radio" name="vi_hall" value="1" <?php echo $write['vi_hall']=="1" ? "checked":""?> /> 불량
			</td>
			</tr>
			<tr class="flag_hide">
			<th>간판 유지 관리상태</th>
			<td>
				<input type="radio" name="vi_sign" value="0" <?php echo $write['vi_sign']=="0" ? "checked":""?> /> 양호
				&nbsp;&nbsp;&nbsp;
				<input type="radio" name="vi_sign" value="1" <?php echo $write['vi_sign']=="1" ? "checked":""?> /> 불량
			</td>
			</tr>
			<tr class="flag_hide">
			<th>쇼 윈도우 및 사인물<br />유지 관리상태</th>
			<td>
				<input type="radio" name="vi_show" value="0" <?php echo $write['vi_show']=="0" ? "checked":""?> /> 양호
				&nbsp;&nbsp;&nbsp;
				<input type="radio" name="vi_show" value="1" <?php echo $write['vi_show']=="1" ? "checked":""?> /> 불량
			</td>
			</tr>
			<tr class="flag_hide">
			<th>카운터 및 주방<br />유지 관리상태</th>
			<td>
				<input type="radio" name="vi_cash" value="0" <?php echo $write['vi_cash']=="0" ? "checked":""?> /> 양호
				&nbsp;&nbsp;&nbsp;
				<input type="radio" name="vi_cash" value="1" <?php echo $write['vi_cash']=="1" ? "checked":""?> /> 불량
			</td>
			</tr>
			<tr class="flag_hide">
			<th>유니폼 착용 유무</th>
			<td>
				<input type="radio" name="vi_uni" value="0" <?php echo $write['vi_uni']=="0" ? "checked":""?> /> 유
				&nbsp;&nbsp;&nbsp;
				<input type="radio" name="vi_uni" value="1" <?php echo $write['vi_uni']=="1" ? "checked":""?> /> 무
			</td>
			</tr>
			<tr>
			<th>파일첨부</th>
			<td>
				<?php
				$fi0 = $write['vi_file0'];
				$fi1 = $write['vi_file1'];

				$vi_fi0 = str_replace("../../data/file/visit/", "", $fi0);
				$vi_fi1 = str_replace("../../data/file/visit/", "", $fi1);
				?>
				<input type="file" name="vi_file0" style="width:80%;margin:7px 0;border:none" /> <?php echo $vi_fi0;?><br />
				<input type="file" name="vi_file1" style="width:80%;margin-bottom:7px;border:none" /> <?php echo $vi_fi1;?>
			</td>
			</tr>
			<tr>
			<th colspan="2" style="text-align:center">내용</th>
			</tr>
			<tr>
			<td colspan="2" style="padding:0px;"><textarea name="vi_content" rows="15" class="tareawd"><?php echo $write['vi_content']?></textarea></td>
			</tr>
			</table>
			<br />
			<style>
			span.confirm_area {cursor:pointer}
			</style>
			<p style="margin-right:10px;">점주 확인 : <input style="width:50px;height:20px;" type="text" name="vi_confirm" value="<?php echo $write['vi_confirm']?>" /> <span class="confirm_area">인(서명)</span></p>
		</div>
		<br />
		<input type="image" src="<?php echo $g4['path']?>/m/img/btn_write.gif" style="border:0" />
		<img src="<?php echo $g4['path']?>/m/img/btn_exit.gif" class="btn_list" style="border:0;cursor:pointer" />
		<?php
		if($w == "")
		{
			$j_data = $_REQUEST['j_data'];
		?>
			<input type="hidden" name="j_data" id="j_data" value="<?php echo $j_data?>" />
		<?
		}
		else if ($w == "u")
		{
		?>
			<img src="<?php echo $write['j_data']?>" style="width:100%" />
		<?
		}
		?>
	</form>
</div>
<br />

<script>
$(".btn_list").click(function() {
	//history.back();
	location.href = "cancel";
});

$(".confirm_area").click(function() {
	//window.open("http://augustin.co.kr/m/android/confirm_code_a.php#simple","confirm","menubar=no,toolbar=no,location=no,scrollbars=no,status=no,fullscreen=no");

	//location.href="/m/android/confirm_code_a.php?branch=<?=$_GET['branch']?>&id=<?=$_GET['id']?>#simple";
	location.href="/m/android/confirm_code_a.php#simple";
});
function closeW(j_data)
{
	//var j_data = j_data;
	//self.close();
}
</script>

<script>
	function checkNumber()
	{
		var objEv = event.srcElement;
		var numPattern = /([^0-9])/;
		var numPattern = objEv.value.match(numPattern);

		if (numPattern != null)
		{
			alert("매출 : 숫자만 입력");
			objEv.value="";
			objEv.focus();
			return false;
		}
	}
</script>

<? //include_once("$g4[path]/m/branch/adm_tail.php");?>
